<template>
    <div class="page-store-platform-store-present bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="text-align: center; background: white; width: 1700px;">
                <div class="tr">
                    <div class="td text-center bold" style="width: 100px;">秒杀状态</div>
                    <div class="td text-center bold" style="width: 100px;">
                        <div style="width: 100px;">商品图片</div>
                    </div>
                    <div class="td text-center bold" style="width: 250px;">标题</div>
                    <div class="td text-center bold" style="width: 150px;">规格</div>
                    <div class="td text-center bold" style="width: 150px;">颜色</div>
                    <div class="td text-center bold" style="width: 100px;">秒杀价格</div>
                    <div class="td text-center bold" style="width: 100px;">秒杀数量</div>
                    <div class="td text-center bold" style="width: 150px;">已成功秒杀数量</div>
                    <div class="td text-center bold" style="width: 200px;">开始时间</div>
                    <div class="td text-center bold" style="width: 200px;">结束时间</div>
                    <div class="td text-center bold" style="width: 100px;">状态</div>
                    <div class="td text-center bold" style="width: 100px;">操作</div>
                </div>
                <div class="tr" v-for="(item, index)  in tbSeckillGoodsList" :key="index">
                    <div class="td text-center" style="width: 100px;">{{item.seckillStatusText}}</div>
                    <div class="td text-center" style="width: 110px;">
                        <myImg :obj="item" :sysFile="{fkId: item.sysFileFkId}" :key="item.id"
                               :customStyle="'pointer-events: none; height: 100px;  width:100px; background-size: cover; background-repeat: no-repeat; background-position: center;'"
                               :defaultUrl="'/pages/sub/sub2-store-platform/static/default-image/goods.jpg'"
                               :imageView="'imageView2/1/w/200/h/200'"
                        ></myImg>
                    </div>
                    <div class="td text-center" style="width: 250px;">{{'item.tbGoods.title' | toValue(item)}}</div>
                    <div class="td text-center" style="width: 150px;">{{'item.tbGoodsSpecification.name' | toValue(item)}}</div>
                    <div class="td text-center" style="width: 150px;">{{'item.tbTbGoodsColor.name' | toValue(item)}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.seckillPrice}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.seckillNumber}}</div>
                    <div class="td text-center" style="width: 150px;">{{item.orderNum}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.startTime}}</div>
                    <div class="td text-center" style="width: 200px;">{{item.endTime}}</div>
                    <div class="td text-center" style="width: 100px;">{{item.statusText}}</div>
                    <div class="td text-center" style="width: 100px;">
                        <div style="margin-top: 10px; text-decoration: underline;"
                             @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-seckill/store-platform-seckill-goods/store-platform-seckill-goods-edit/index', null, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; text-decoration: underline;" @click="deleteItem(item, index)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbSeckillGoodsList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-seckill/store-platform-seckill-goods/store-platform-seckill-goods-select/index')">
                添加
            </label>
        </div>
    </div>
</template>

<script>
    import {CommonUtil} from "@/dev/core/utils/common.util";
    import {TbSeckillGoodsService} from "@/dev/services/tb-seckill-goods.service";
    import myImg from '@/components/my-img'

    export default {
        data() {
            return {
                tbSeckillGoodsList: []
            }
        },
        components: {
            myImg
        },
        onShow() {
            this.doRefresh(this.tbSeckillGoodsList);
        },
        methods: {
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbSeckillGoodsService().findTableListByStore({
                    pagination: this.pagination,
                    data: {
                        storeId: _self.globalVariable.userInfo.tbStore.id,
                    }
                }).then(result => {
                    console.log(_self.tbSeckillGoodsList);
                    _self.pagination.refreshPage(result);
                    result.list.forEach(item => {
                        item.sysFileFkId = item.tbGoodsSpecification.id;
                        if (item.tbTbGoodsColor) {
                            item.sysFileFkId = item.tbTbGoodsColor.id;
                        }
                    });
                    _self.tbSeckillGoodsList = [..._self.tbSeckillGoodsList, ...result.list]
                })
            },
            /**
             * 删除规格
             * @param item
             * @param index
             */
            deleteItem(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbSeckillGoodsService().batchDeleteTbSeckillGoodsByIds(item.id).then(result => {
                                _self.tbSeckillGoodsList.splice(index, 1);
                                CommonUtil.toast('删除成功');
                            });
                        }
                    }
                });
            }
        }
    }
</script>
